<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of GEplot</title>
  <meta name="keywords" content="GEplot">
  <meta name="description" content="">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
  <script type="text/javascript">
    if (top.frames.length == 0) { top.location = "../../index.html"; };
  </script>
</head>
<body>
<a name="_top"></a>
<!-- ../menu.html trunk --><!-- menu.html utils -->
<h1>GEplot
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong></strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>function GEplot(filename,Lat,Lon,style,opt11,opt12,opt21,opt22) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment">
 function GEplot(filename,Lat,Lon,style,opt11,opt12,opt21,opt22)

 Description: creates a file in kmz format that can be opened into Google Earth.
    GEplot uses the same syntax as the traditional plot function but
    requires Latitude and Longitudd (WGS84) instead of x and y (note that Lat is
    the first argument).
    If you need to convert from UTM to Lat/Lon you may use utm2deg.m also
    available at Matlab Central

 Arguments:
    filename Example 'rafael', will become 'rafael.kmz'.  The same name
             will appear inside Temporary Places in Google Earth as a layer.
    dot_size Approximate size of the mark, in meters
    Lat, Lon Vectors containing Latitudes and Longitudes.  The number of marks
             created by this function is equal to the length of Lat/Lon vectors
(opt)style   allows for specifying symbols and colors (line styles are not
             supported by Google Earth currently. (see bellow)
(opt)opt...   allows for specifying symbol size and line width (see bellow)

 Example:
    GEplot('my_track',Lat,Lon,'o-r','MarkerSize',10,'LineWidth',3)
    GEplot('my_track',Lat,Lon)

 Plot style parameters implemented in GEplot
            color               symbol                line style
            -----------------------------------------------------------
            b     blue          .     point              -    solid
            g     green         o     circle          (none)  no line
            r     red           x     x-mark               
            c     cyan          +     plus                  
            m     magenta       *     star             
            y     yellow        s     square
            k     black         d     diamond
            w     white (new)   S     filled square (new)
                                D     filled diamond (new)
                                O     filled circle=big dot (new)

 Plot properties: 'MarkerSize' 'LineWidth'       

 Additional Notes:
 'Hold on' and 'Hold off' were not implemented since one can generate a
    .kmz file for each plot and open all simultaneously within GE.
 Unless you have a lot of data point it is recomended to show the symbols
    since they are created in a separate folder so within Google Earth it
    is very easy to show/hide the line or the symbols.
 Current kml/kmz format does not support different linestyles, just solid.
    Nevertheless it is possible to define the opacity of the color (the 
    first FF in the color definition means no transparency).
 Within Matlab, it is possible to generate a second plot with the 
    same name, then you just need to select File/Revert within GE to update.


 Author: Rafael Palacios, Universidad Pontificia Comillas
 http://www.iit.upcomillas.es/palacios
 November 2006
 Version 1.1: Fixed an error while plotting graphs without symbols.</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
</ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
</ul>
<!-- crossreference -->



<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function GEplot(filename,Lat,Lon,style,opt11,opt12,opt21,opt22)</a>
0002 <span class="comment">%</span>
0003 <span class="comment">% function GEplot(filename,Lat,Lon,style,opt11,opt12,opt21,opt22)</span>
0004 <span class="comment">%</span>
0005 <span class="comment">% Description: creates a file in kmz format that can be opened into Google Earth.</span>
0006 <span class="comment">%    GEplot uses the same syntax as the traditional plot function but</span>
0007 <span class="comment">%    requires Latitude and Longitudd (WGS84) instead of x and y (note that Lat is</span>
0008 <span class="comment">%    the first argument).</span>
0009 <span class="comment">%    If you need to convert from UTM to Lat/Lon you may use utm2deg.m also</span>
0010 <span class="comment">%    available at Matlab Central</span>
0011 <span class="comment">%</span>
0012 <span class="comment">% Arguments:</span>
0013 <span class="comment">%    filename Example 'rafael', will become 'rafael.kmz'.  The same name</span>
0014 <span class="comment">%             will appear inside Temporary Places in Google Earth as a layer.</span>
0015 <span class="comment">%    dot_size Approximate size of the mark, in meters</span>
0016 <span class="comment">%    Lat, Lon Vectors containing Latitudes and Longitudes.  The number of marks</span>
0017 <span class="comment">%             created by this function is equal to the length of Lat/Lon vectors</span>
0018 <span class="comment">%(opt)style   allows for specifying symbols and colors (line styles are not</span>
0019 <span class="comment">%             supported by Google Earth currently. (see bellow)</span>
0020 <span class="comment">%(opt)opt...   allows for specifying symbol size and line width (see bellow)</span>
0021 <span class="comment">%</span>
0022 <span class="comment">% Example:</span>
0023 <span class="comment">%    GEplot('my_track',Lat,Lon,'o-r','MarkerSize',10,'LineWidth',3)</span>
0024 <span class="comment">%    GEplot('my_track',Lat,Lon)</span>
0025 <span class="comment">%</span>
0026 <span class="comment">% Plot style parameters implemented in GEplot</span>
0027 <span class="comment">%            color               symbol                line style</span>
0028 <span class="comment">%            -----------------------------------------------------------</span>
0029 <span class="comment">%            b     blue          .     point              -    solid</span>
0030 <span class="comment">%            g     green         o     circle          (none)  no line</span>
0031 <span class="comment">%            r     red           x     x-mark</span>
0032 <span class="comment">%            c     cyan          +     plus</span>
0033 <span class="comment">%            m     magenta       *     star</span>
0034 <span class="comment">%            y     yellow        s     square</span>
0035 <span class="comment">%            k     black         d     diamond</span>
0036 <span class="comment">%            w     white (new)   S     filled square (new)</span>
0037 <span class="comment">%                                D     filled diamond (new)</span>
0038 <span class="comment">%                                O     filled circle=big dot (new)</span>
0039 <span class="comment">%</span>
0040 <span class="comment">% Plot properties: 'MarkerSize' 'LineWidth'</span>
0041 <span class="comment">%</span>
0042 <span class="comment">% Additional Notes:</span>
0043 <span class="comment">% 'Hold on' and 'Hold off' were not implemented since one can generate a</span>
0044 <span class="comment">%    .kmz file for each plot and open all simultaneously within GE.</span>
0045 <span class="comment">% Unless you have a lot of data point it is recomended to show the symbols</span>
0046 <span class="comment">%    since they are created in a separate folder so within Google Earth it</span>
0047 <span class="comment">%    is very easy to show/hide the line or the symbols.</span>
0048 <span class="comment">% Current kml/kmz format does not support different linestyles, just solid.</span>
0049 <span class="comment">%    Nevertheless it is possible to define the opacity of the color (the</span>
0050 <span class="comment">%    first FF in the color definition means no transparency).</span>
0051 <span class="comment">% Within Matlab, it is possible to generate a second plot with the</span>
0052 <span class="comment">%    same name, then you just need to select File/Revert within GE to update.</span>
0053 <span class="comment">%</span>
0054 <span class="comment">%</span>
0055 <span class="comment">% Author: Rafael Palacios, Universidad Pontificia Comillas</span>
0056 <span class="comment">% http://www.iit.upcomillas.es/palacios</span>
0057 <span class="comment">% November 2006</span>
0058 <span class="comment">% Version 1.1: Fixed an error while plotting graphs without symbols.</span>
0059 <span class="comment">%</span>
0060 
0061 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span>
0062 <span class="comment">% Argument checking</span>
0063 <span class="comment">%</span>
0064 error(nargchk(3, 8, nargin));  <span class="comment">%3 arguments required, 8 maximum</span>
0065 n1=length(Lat);
0066 n2=length(Lon);
0067 <span class="keyword">if</span> (n1~=n2)
0068    error(<span class="string">'Lat and Lon vectors should have the same length'</span>);
0069 <span class="keyword">end</span>
0070 <span class="keyword">if</span> (nargin==5 || nargin==7)
0071     error(<span class="string">'size arguments must be &quot;MarkerSize&quot; or &quot;LineWidth&quot; strings followed by a number'</span>);
0072 <span class="keyword">end</span>
0073 
0074 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span>
0075 <span class="comment">% symbol size and line width</span>
0076 <span class="comment">%</span>
0077 markersize=7; <span class="comment">%matlab default</span>
0078 linewidth=2;  <span class="comment">%matlab default is 0.5, too thin for map overlay</span>
0079 <span class="keyword">if</span> (nargin==6)
0080     <span class="keyword">if</span> (strcmpi(opt11,<span class="string">'markersize'</span>)==1)
0081         markersize=opt12;
0082     <span class="keyword">elseif</span> (strcmpi(opt11,<span class="string">'linewidth'</span>)==1)
0083         linewidth=opt12;
0084     <span class="keyword">else</span>
0085         error(<span class="string">'size arguments must be &quot;MarkerSize&quot; or &quot;LineWidth&quot; strings followed by a number'</span>);
0086     <span class="keyword">end</span>
0087 <span class="keyword">end</span>
0088 <span class="keyword">if</span> (nargin==8)
0089     <span class="keyword">if</span> (strcmpi(opt21,<span class="string">'markersize'</span>)==1)
0090         markersize=opt22;
0091     <span class="keyword">elseif</span> (strcmpi(opt21,<span class="string">'linewidth'</span>)==1)
0092         linewidth=opt22;
0093     <span class="keyword">else</span>
0094         error(<span class="string">'size arguments must be &quot;MarkerSize&quot; or &quot;LineWidth&quot; strings followed by a number'</span>);
0095     <span class="keyword">end</span>
0096 <span class="keyword">end</span>
0097        
0098 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span>
0099 <span class="comment">% symbol, line style and color</span>
0100 <span class="comment">%</span>
0101 symbol=<span class="string">'none'</span>;
0102 iconfilename=<span class="string">'none'</span>;
0103 linestyle=<span class="string">'-'</span>;
0104 color=<span class="string">'b'</span>;
0105 colorstring=<span class="string">'ffff0000'</span>;
0106 
0107 <span class="keyword">if</span> (nargin&gt;=4)
0108     <span class="comment">%linestyle</span>
0109     <span class="keyword">if</span> (strfind(style,<span class="string">'-'</span>))
0110         linestyle=<span class="string">'-'</span>;
0111     <span class="keyword">else</span>
0112         linestyle=<span class="string">'none'</span>;
0113     <span class="keyword">end</span>
0114 
0115     <span class="comment">%symbol</span>
0116     <span class="keyword">if</span> (strfind(style,<span class="string">'.'</span>)), symbol=<span class="string">'.'</span>; iconfilename=<span class="string">'dot'</span>; <span class="keyword">end</span>
0117     <span class="keyword">if</span> (strfind(style,<span class="string">'o'</span>)), symbol=<span class="string">'o'</span>; iconfilename=<span class="string">'circle'</span>; <span class="keyword">end</span>
0118     <span class="keyword">if</span> (strfind(style,<span class="string">'x'</span>)), symbol=<span class="string">'x'</span>; iconfilename=<span class="string">'x'</span>; <span class="keyword">end</span>
0119     <span class="keyword">if</span> (strfind(style,<span class="string">'+'</span>)), symbol=<span class="string">'+'</span>; iconfilename=<span class="string">'plus'</span>; <span class="keyword">end</span>
0120     <span class="keyword">if</span> (strfind(style,<span class="string">'*'</span>)), symbol=<span class="string">'*'</span>; iconfilename=<span class="string">'star'</span>; <span class="keyword">end</span>
0121     <span class="keyword">if</span> (strfind(style,<span class="string">'s'</span>)), symbol=<span class="string">'s'</span>; iconfilename=<span class="string">'square'</span>; <span class="keyword">end</span>
0122     <span class="keyword">if</span> (strfind(style,<span class="string">'d'</span>)), symbol=<span class="string">'d'</span>; iconfilename=<span class="string">'diamond'</span>; <span class="keyword">end</span>
0123     <span class="keyword">if</span> (strfind(style,<span class="string">'S'</span>)), symbol=<span class="string">'S'</span>; iconfilename=<span class="string">'Ssquare'</span>; <span class="keyword">end</span>
0124     <span class="keyword">if</span> (strfind(style,<span class="string">'D'</span>)), symbol=<span class="string">'D'</span>; iconfilename=<span class="string">'Sdiamon'</span>; <span class="keyword">end</span>
0125     <span class="keyword">if</span> (strfind(style,<span class="string">'O'</span>)), symbol=<span class="string">'O'</span>; iconfilename=<span class="string">'dot'</span>; <span class="keyword">end</span>
0126     <span class="keyword">if</span> (strfind(style,<span class="string">'0'</span>)), symbol=<span class="string">'O'</span>; iconfilename=<span class="string">'dot'</span>; <span class="keyword">end</span>
0127 
0128     <span class="comment">%color</span>
0129     <span class="keyword">if</span> (strfind(style,<span class="string">'b'</span>)), color=<span class="string">'b'</span>; colorstring=<span class="string">'ffff0000'</span>; <span class="keyword">end</span>
0130     <span class="keyword">if</span> (strfind(style,<span class="string">'g'</span>)), color=<span class="string">'g'</span>; colorstring=<span class="string">'ff00ff00'</span>; <span class="keyword">end</span>
0131     <span class="keyword">if</span> (strfind(style,<span class="string">'r'</span>)), color=<span class="string">'r'</span>; colorstring=<span class="string">'ff0000ff'</span>; <span class="keyword">end</span>
0132     <span class="keyword">if</span> (strfind(style,<span class="string">'c'</span>)), color=<span class="string">'c'</span>; colorstring=<span class="string">'ffffff00'</span>; <span class="keyword">end</span>
0133     <span class="keyword">if</span> (strfind(style,<span class="string">'m'</span>)), color=<span class="string">'m'</span>; colorstring=<span class="string">'ffff00ff'</span>; <span class="keyword">end</span>
0134     <span class="keyword">if</span> (strfind(style,<span class="string">'y'</span>)), color=<span class="string">'y'</span>; colorstring=<span class="string">'ff00ffff'</span>; <span class="keyword">end</span>
0135     <span class="keyword">if</span> (strfind(style,<span class="string">'k'</span>)), color=<span class="string">'k'</span>; colorstring=<span class="string">'ff000000'</span>; <span class="keyword">end</span>
0136     <span class="keyword">if</span> (strfind(style,<span class="string">'w'</span>)), color=<span class="string">'w'</span>; colorstring=<span class="string">'ffffffff'</span>; <span class="keyword">end</span>
0137 <span class="keyword">end</span>
0138 
0139 iconfilename=strcat(<span class="string">'GEimages/'</span>,iconfilename,<span class="string">'_'</span>,color,<span class="string">'.png'</span>);
0140 <span class="keyword">if</span> (symbol==<span class="string">'.'</span>) 
0141     markersize=markersize/5;
0142 <span class="keyword">end</span>
0143 
0144 
0145 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%</span>
0146 <span class="comment">% Creating kml file</span>
0147 <span class="comment">%</span>
0148 fp=fopen(strcat(filename,<span class="string">'.kml'</span>),<span class="string">'w'</span>);
0149 <span class="keyword">if</span> (fp==-1)
0150     message=disp(<span class="string">'Unable to open file %s.kml'</span>,filename);
0151     error(message);
0152 <span class="keyword">end</span>
0153 fprintf(fp,<span class="string">'&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\n'</span>);
0154 fprintf(fp,<span class="string">'&lt;kml xmlns=&quot;http://earth.google.com/kml/2.1&quot;&gt;\n'</span>);
0155 fprintf(fp,<span class="string">'&lt;Document&gt;\n'</span>);
0156 fprintf(fp,<span class="string">'&lt;name&gt;%s&lt;/name&gt;\n'</span>,strcat(filename,<span class="string">'.kml'</span>));
0157 fprintf(fp,<span class="string">'&lt;description&gt;Graph generated in Matlab (using GEplot.m by Rafael Palacios)&lt;/description&gt;\n'</span>);
0158 <span class="comment">%</span>
0159 <span class="comment">%Symbol styles definition</span>
0160 fprintf(fp,<span class="string">'&lt;Style id=&quot;mystyle&quot;&gt;\n'</span>);
0161 fprintf(fp,<span class="string">'   &lt;IconStyle&gt;\n'</span>);
0162 fprintf(fp,<span class="string">'      &lt;scale&gt;%.2f&lt;/scale&gt;\n'</span>,markersize/14); <span class="comment">%scale adjusted for .png image sizes</span>
0163 fprintf(fp,<span class="string">'      &lt;Icon&gt;&lt;href&gt;%s&lt;/href&gt;&lt;/Icon&gt;\n'</span>,iconfilename);
0164 fprintf(fp,<span class="string">'   &lt;/IconStyle&gt;\n'</span>);
0165 fprintf(fp,<span class="string">'   &lt;LineStyle&gt;\n'</span>);
0166 fprintf(fp,<span class="string">'      &lt;color&gt;%s&lt;/color&gt;\n'</span>,colorstring);
0167 fprintf(fp,<span class="string">'      &lt;width&gt;%d&lt;/width&gt;\n'</span>,linewidth);
0168 fprintf(fp,<span class="string">'   &lt;/LineStyle&gt;\n'</span>);
0169 fprintf(fp,<span class="string">'&lt;/Style&gt;\n'</span>);
0170 fprintf(fp,<span class="string">'\n'</span>);
0171 
0172 
0173 <span class="keyword">if</span> (linestyle==<span class="string">'-'</span>)
0174     fprintf(fp,<span class="string">'    &lt;Placemark&gt;\n'</span>);
0175     fprintf(fp,<span class="string">'      &lt;description&gt;&lt;![CDATA[Line created with Matlab GEplot.m]]&gt;&lt;/description&gt;\n'</span>);
0176     fprintf(fp,<span class="string">'      &lt;name&gt;Line&lt;/name&gt;\n'</span>);
0177     fprintf(fp,<span class="string">'      &lt;visibility&gt;1&lt;/visibility&gt;\n'</span>);
0178     fprintf(fp,<span class="string">'      &lt;open&gt;1&lt;/open&gt;\n'</span>);
0179     fprintf(fp,<span class="string">'      &lt;styleUrl&gt;mystyle&lt;/styleUrl&gt;\n'</span>);
0180     fprintf(fp,<span class="string">'      &lt;LineString&gt;\n'</span>);
0181     fprintf(fp,<span class="string">'        &lt;extrude&gt;0&lt;/extrude&gt;\n'</span>);
0182     fprintf(fp,<span class="string">'        &lt;tessellate&gt;0&lt;/tessellate&gt;\n'</span>);
0183     fprintf(fp,<span class="string">'        &lt;altitudeMode&gt;clampToGround&lt;/altitudeMode&gt;\n'</span>);
0184     fprintf(fp,<span class="string">'        &lt;coordinates&gt;\n'</span>);
0185     <span class="keyword">for</span> k=1:n1
0186       fprintf(fp,<span class="string">'%11.6f,%11.6f,0\n'</span>,Lon(k),Lat(k));
0187     <span class="keyword">end</span>
0188     fprintf(fp,<span class="string">'        &lt;/coordinates&gt;\n'</span>);
0189     fprintf(fp,<span class="string">'      &lt;/LineString&gt;\n'</span>);
0190     fprintf(fp,<span class="string">'    &lt;/Placemark&gt;\n'</span>);
0191 <span class="keyword">end</span>
0192 
0193 <span class="keyword">if</span> (strcmp(symbol,<span class="string">'none'</span>)==0)
0194 fprintf(fp,<span class="string">'    &lt;Folder&gt;\n'</span>);
0195 fprintf(fp,<span class="string">'      &lt;name&gt;Data points&lt;/name&gt;\n'</span>);
0196 <span class="keyword">for</span> k=1:n1
0197     fprintf(fp,<span class="string">'      &lt;Placemark&gt;\n'</span>);
0198     fprintf(fp,<span class="string">'         &lt;description&gt;&lt;![CDATA[Point created with Matlab GEplot.m]]&gt;&lt;/description&gt;\n'</span>);
0199 <span class="comment">%    fprintf(fp,'         &lt;name&gt;Point %d&lt;/name&gt;\n',k);  %you may add point labels here</span>
0200     fprintf(fp,<span class="string">'         &lt;visibility&gt;1&lt;/visibility&gt;\n'</span>);
0201     fprintf(fp,<span class="string">'         &lt;open&gt;1&lt;/open&gt;\n'</span>);
0202     fprintf(fp,<span class="string">'         &lt;styleUrl&gt;#mystyle&lt;/styleUrl&gt;\n'</span>);
0203     fprintf(fp,<span class="string">'         &lt;Point&gt;\n'</span>);
0204     fprintf(fp,<span class="string">'           &lt;coordinates&gt;\n'</span>);
0205     fprintf(fp,<span class="string">'%11.6f,%11.6f,0\n'</span>,Lon(k),Lat(k));
0206     fprintf(fp,<span class="string">'           &lt;/coordinates&gt;\n'</span>);
0207     fprintf(fp,<span class="string">'         &lt;/Point&gt;\n'</span>);
0208     fprintf(fp,<span class="string">'      &lt;/Placemark&gt;\n'</span>);
0209 <span class="keyword">end</span>
0210 fprintf(fp,<span class="string">'    &lt;/Folder&gt;\n'</span>);
0211 <span class="keyword">end</span>
0212 
0213 fprintf(fp,<span class="string">'&lt;/Document&gt;\n'</span>);
0214 fprintf(fp,<span class="string">'&lt;/kml&gt;\n'</span>);
0215 
0216 fclose(fp);
0217 
0218 <span class="keyword">if</span> (strcmp(symbol,<span class="string">'none'</span>)==1)
0219    zip(filename,{strcat(filename,<span class="string">'.kml'</span>)});
0220 <span class="keyword">else</span>
0221    zip(filename,{strcat(filename,<span class="string">'.kml'</span>), iconfilename});
0222 <span class="keyword">end</span>
0223 movefile(strcat(filename,<span class="string">'.zip'</span>),strcat(filename,<span class="string">'.kmz'</span>));
0224 delete(strcat(filename,<span class="string">'.kml'</span>));</pre></div>
<hr><address>Generated on Tue 30-Apr-2013 10:18:12 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" target="_parent">m2html</a></strong> &copy; 2005</address>
</body>
</html>